home *** CD-ROM | disk | FTP | other *** search
/ Chip 2007 January, February, March & April / Chip-Cover-CD-2007-02.iso / Pakiet bezpieczenstwa / mini Pentoo LiveCD 2006.1 / mpentoo-2006.1.iso / livecd.squashfs / usr / share / eselect / modules / opengl.eselect < prev    next >
Text File  |  2006-04-12  |  11KB  |  353 lines

  1. # Copyright 1999-2004 Gentoo Foundation
  2. # Distributed under the terms of the GNU General Public License v2
  3. # $Id: opengl.eselect 237 2005-10-19 16:41:14Z eradicator $
  4. # Author:  Martin Schlemmer <azarah@gentoo.org>
  5. # Further modifications by Donnie Berkholz <spyderous@gentoo.org>
  6. # Further modifications based off submissions to bug #54984 <cyfred@gentoo.org>
  7. # Further modifications by Jeremy Huddleston <eradicator@gentoo.org>
  8. # Made into eselect module by Jeremy Huddleston <eradicator@gentoo.org>
  9.  
  10. inherit multilib portage config
  11.  
  12. # Eselect data
  13. DESCRIPTION="Manage the OpenGL implementation used by your system"
  14. MAINTAINER="x11-drivers@gentoo.org"
  15. SVN_DATE='$Date: 2005-10-19 09:41:14 -0700 (Wed, 19 Oct 2005) $'
  16. VERSION=$(svn_date_to_version "${SVN_DATE}" )
  17. EBUILD_VERSION="1.0.3"
  18.  
  19. # Our data
  20. ENV_FILE="${ROOT}/etc/env.d/03opengl"
  21. PREFIX="${ROOT}/usr"
  22. DST_PREFIX="${ROOT}/usr"
  23. USE_PROFILE_HEADERS="no"
  24.  
  25. check_version() {
  26.     if portageq has_version ${ROOT:-/} 'x11-base/xorg-x11'; then
  27.         if ! portageq has_version ${ROOT:-/} '>=x11-base/xorg-x11-6.8.0-r4'; then
  28.             die -q "This version requires >=x11-base/xorg-x11-6.8.0-r4"
  29.         fi
  30.     fi
  31. }
  32.  
  33. get_current_implementation() {
  34.     local ret
  35.     local ldpath=$(load_config "${ENV_FILE}" LDPATH)
  36.     local opengl_profile=$(load_config "${ENV_FILE}" OPENGL_PROFILE)
  37.         
  38.     if [[ -n ${opengl_profile} ]] ; then
  39.         ret="${opengl_profile}"
  40.     elif [[ -n ${ldpath} ]] ; then
  41.         ret="${ldpath%%:*}"
  42.         ret="${ret##*opengl/}"
  43.         ret="${ret%/lib*}"
  44.     fi
  45.  
  46.     echo ${ret}
  47. }
  48.  
  49. get_implementations() {
  50.     local ret dir
  51.     for x in $(list_libdirs) ; do
  52.         for dir in "${PREFIX}/${x}"/opengl/* ; do
  53.             [[ -d ${dir} && $(basename "${dir}") != "global" ]] || continue
  54.             has $(basename "${dir}") ${ret} && continue
  55.             ret=${ret:+${ret} }$(basename "${dir}")
  56.         done
  57.     done
  58.  
  59.     echo ${ret}
  60. }
  61.  
  62. setup_lib_symlinks() {
  63.     local profile_libdir=${1}
  64.     local libdir=${2}
  65.     local file
  66.  
  67.     mkdir -p "${libdir}" || die "Failed to create ${libdir}"
  68.  
  69.     pushd "${libdir}" &> /dev/null
  70.         # First remove old symlinks
  71.         for file in libGL{,core}.{a,so,la} ; do
  72.             if [[ -h ${file} ]] ; then
  73.                 rm -f "${file}" || die -q "Failed to delete ${file}"
  74.             fi
  75.         done
  76.  
  77.         # Note that we don't do .so*, just .so on purpose.  The
  78.         # loader knows to look in the profile dir, and the
  79.         # linked just needs the .so
  80.         for file in ${profile_libdir}/libGL{,core}.{so,a,la}; do
  81.             [[ -f ${file} ]] || continue
  82.             if [[ -f $(basename "${file}") ]] ; then
  83.                 rm -f "$(basename "${file}")" || die -q "Failed to delete ${libdir}/$(basename "${file}")"
  84.             fi
  85.  
  86.             # Fix libtool archives (#48297)
  87.             if [[ ${file%.la} != ${file} ]] ; then
  88.                 sed "s:${profile_libdir}:${libdir}:g" "${file}" > "$(basename "${file}")" || die -q "Failed to create ${libdir}/$(basename "${file}")"
  89.             else
  90.                 ln -s "${file}" || die -q "Failed to create ${libdir}/$(basename "${file}")"
  91.             fi
  92.         done
  93.     popd &> /dev/null
  94. }
  95.  
  96. set_new_implementation() {
  97.     local gl_implem=${1}
  98.     local avail_implems=$(get_implementations)
  99.  
  100.     check_version
  101.  
  102.     # Set a sane umask... bug #83115
  103.     umask 022
  104.  
  105.     if ! has ${gl_implem} ${avail_implems}; then
  106.         die -q "Invalid profile selected."
  107.     fi
  108.  
  109.     echo -n "Switching to ${gl_implem} OpenGL interface..."
  110.         if [[ -f ${ENV_FILE} ]] ; then
  111.             rm -f "${ENV_FILE}" || die -q "Failed to remove ${ENV_FILE}"
  112.         fi
  113.  
  114.         local libdir
  115.         for libdir in $(list_libdirs); do
  116.             # Special case handling of lib32 because it can be a symlink to
  117.             # emul libs
  118.             # Kill this special case once amd64's 2004.3 crap is gone =) --eradicator
  119.             if [[ ${libdir} = "lib32" ]] ; then
  120.                 [[ -d ${PREFIX}/${libdir}/opengl ]] || continue
  121.             else
  122.                 [[ -d ${PREFIX}/${libdir}/opengl && ! -h ${PREFIX}/${libdir} ]] || continue
  123.             fi
  124.  
  125.             # Fallback on xorg-x11 if we don't have this implementation for this libdir.
  126.             local gl_local
  127.             if [[ ! -d ${PREFIX}/${libdir}/opengl/"${gl_implem}" ]] ; then
  128.                 gl_local="xorg-x11"
  129.             else
  130.                 gl_local="${gl_implem}"
  131.             fi
  132.  
  133.             setup_lib_symlinks "${PREFIX}/${libdir}/opengl/${gl_local}/lib" "${DST_PREFIX}/${libdir}"
  134.         
  135.             if [[ -e ${PREFIX}/${libdir}/opengl/${gl_local}/lib/tls ]] ; then
  136.                 setup_lib_symlinks "${PREFIX}/${libdir}/opengl/${gl_local}/lib/tls" "${DST_PREFIX}/${libdir}/tls"
  137.             fi
  138.  
  139.             local moduledir
  140.             if [[ -e ${DST_PREFIX}/${libdir}/xorg/modules ]] ; then
  141.                 moduledir="xorg/modules"
  142.             else
  143.                 moduledir="modules"
  144.             fi
  145.  
  146.             if [[ -e ${PREFIX}/${libdir}/opengl/${gl_local}/extensions ]] ; then
  147.                 mkdir -p "${DST_PREFIX}/${libdir}/${moduledir}/extensions" || die "Failed to create ${DST_PREFIX}/${libdir}/${moduledir}/extensions"
  148.                 pushd "${DST_PREFIX}/${libdir}/${moduledir}/extensions" &> /dev/null
  149.                     # First remove old symlinks
  150.                     for file in libglx.so libglx.a; do
  151.                         if [[ -h ${file} ]] ; then
  152.                             rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/${libdir}/${moduledir}/extensions/${file}"
  153.                         fi
  154.                     done
  155.  
  156.                     for file in ${PREFIX}/${libdir}/opengl/${gl_local}/extensions/*.{so,a,la}; do
  157.                         [[ -f ${file} ]] || continue
  158.                         if [[ -f $(basename "${file}") ]] ; then
  159.                             rm -f "$(basename "${file}")" || die -q "Failed to delete ${DST_PREFIX}/${libdir}/${moduledir}/extensions/$(basename "${file}")"
  160.                         fi
  161.  
  162.                         # Fix libtool archives (#48297)
  163.                         if [[ ${file%.la} != ${file} ]] ; then
  164.                             sed "s:${PREFIX}/[^/]*/opengl/[^/]*/lib:${DST_PREFIX}/${libdir}:g" "${file}" > "$(basename "${file}")" || die -q "Failed to create ${DST_PREFIX}/${libdir}/${moduledir}/extensions/$(basename "${file}")"
  165.                         else
  166.                             ln -s "${file}" || die -q "Failed to create ${libdir}/$(basename "${file}")"
  167.                         fi
  168.                     done
  169.                 popd &> /dev/null
  170.             fi
  171.  
  172.             # Setup the includes
  173.             mkdir -p "${DST_PREFIX}/include/GL" || die "Failed to create ${DST_PREFIX}/include/GL"
  174.             pushd "${DST_PREFIX}/include/GL" &> /dev/null
  175.                 for file in gl.h glx.h glxtokens.h glext.h glxext.h glxmd.h glxproto.h; do
  176.                     # IMPORTANT
  177.                     # It is preferable currently to use the standard glext.h file
  178.                     # however if an OpenGL provider must use a self produced glext.h
  179.                     # then it should be installed to ${gl_implem}/include and the user
  180.                     # can add the --impl-headers option to select it.
  181.  
  182.                     if [[ "${USE_PROFILE_HEADERS}" == "yes" ]] ; then
  183.                         # Check the profile first.
  184.                         if [[ -e ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} ]] ; then
  185.                             if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then
  186.                                 rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")"
  187.                             fi
  188.  
  189.                             ln -s ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")"
  190.                             continue
  191.                         fi
  192.                     fi
  193.  
  194.                     if [[ -e ${PREFIX}/${libdir}/opengl/global/include/${file} ]] ; then
  195.                         if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then
  196.                             rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")"
  197.                         fi
  198.  
  199.                         ln -s ${PREFIX}/${libdir}/opengl/global/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")"
  200.                     elif [[ -e ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} ]] ; then
  201.                         if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then
  202.                             rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")"
  203.                         fi
  204.  
  205.                         ln -s ${PREFIX}/${libdir}/opengl/${gl_implem}/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")"
  206.                     elif [[ -e ${PREFIX}/${libdir}/opengl/xorg-x11/include/${file} ]] ; then
  207.                         if [[ -f ${file} || ( -L ${file} && ! -e ${file} ) ]] ; then
  208.                             rm -f "${file}" || die -q "Failed to delete ${DST_PREFIX}/include/GL/$(basename "${file}")"
  209.                         fi
  210.  
  211.                         ln -s ${PREFIX}/${libdir}/opengl/xorg-x11/include/${file} || die -q "Failed to create ${DST_PREFIX}/include/GL/$(basename "${file}")"
  212.                     fi
  213.                 done
  214.             popd &> /dev/null
  215.  
  216.             # Setup the $LDPATH
  217.             ldpath="${ldpath:+${ldpath}:}${PREFIX}/${libdir}/opengl/${gl_local}/lib"
  218.  
  219.         done
  220.  
  221.         store_config ${ENV_FILE} LDPATH "${ldpath}"
  222.         store_config ${ENV_FILE} OPENGL_PROFILE "${gl_implem}"
  223.  
  224.         eselect env update >& /dev/null
  225.  
  226.     echo " done"
  227. }
  228.  
  229. ### show action ###
  230. describe_show() {
  231.     echo "Print the current OpenGL implementation."
  232. }
  233.  
  234. do_show() {
  235.     local current=$(get_current_implementation)
  236.     if [[ -n ${current} ]] ; then
  237.         echo ${current}
  238.         return 0
  239.     else
  240.         echo "(none)"
  241.         return 2
  242.     fi
  243. }
  244.  
  245. ### list action ###
  246. describe_list() {
  247.     echo "List the available OpenGL implementations."
  248. }
  249.  
  250. do_list() {
  251.     targets=( $(get_implementations) )
  252.     write_list_start "Available OpenGL implementations:"
  253.     if [[ -n ${targets[@]} ]] ; then
  254.         local i
  255.         for (( i = 0 ; i < ${#targets[@]} ; i = i + 1 )) ; do
  256.             [[ ${targets[${i}]} == $(get_current_implementation) ]] \
  257.                 && targets[${i}]="${targets[${i}]} $(highlight '*' )"
  258.         done
  259.         write_numbered_list "${targets[@]}"
  260.     else
  261.         write_kv_list_entry "(none found)" ""
  262.     fi
  263. }
  264.  
  265. ### set action ###
  266. describe_set() {
  267.     echo "Select the OpenGL implementation."
  268. }
  269.  
  270. describe_set_parameters() {
  271.     echo "<target>"
  272. }
  273.  
  274. describe_set_options() {
  275.     echo "<target> : The profile to activate"
  276.     echo "--use-old : If an implementation is already set, use that one instead"
  277.     echo "--prefix=<val> : Set the source prefix (default: /usr)"
  278.     echo "--dst-prefix=<val> : Set the destination prefix (default: /usr)"
  279.     echo "--impl-headers : Override global headers with ones provided by this profile"
  280. #    write_list_start "Extra options for 'set' action:"
  281. #    write_kv_list_entry "<target>" "The profile to activate."
  282. #    write_kv_list_entry "--use-old" "If an implementation is already set, use that one."
  283. #    write_kv_list_entry "--prefix=<val>" "Set the source prefix (default: /usr)"
  284. #    write_kv_list_entry "--dst-prefix=<val>" "Set the destination prefix (default: /usr)"
  285. #    write_kv_list_entry "--impl-headers" "Use headers provided by this implementation to"
  286. #    write_kv_list_entry "" "override golbal ones provided by opengl-update."
  287. #    write_kv_list_entry "" "This was default in <opengl-update-2.2"
  288. }
  289.  
  290. do_set() {
  291.     local action="error"
  292.     local current=$(get_current_implementation)
  293.     local available=$(get_implementations)
  294.     local new
  295.  
  296.     while [[ ${#@} -gt 0 ]] ; do
  297.         local opt=${1}
  298.         shift
  299.         case ${opt} in
  300.             --use-old)
  301.                 if [[ -n ${current} ]] && has ${current} ${available}; then
  302.                     action="old-implementation"
  303.                 fi
  304.             ;;
  305.             --prefix=*)
  306.                 PREFIX=${ROOT}${opt#*=}
  307.                 available=$(get_implementations)
  308.             ;;
  309.             --dst-prefix=*)
  310.                 DST_PREFIX=${ROOT}${opt#*=}
  311.             ;;
  312.             --impl-headers)
  313.                 USE_PROFILE_HEADERS="yes"
  314.             ;;
  315.             *)
  316.                 if [[ ${action} != "old-implementation" ]] ; then
  317.                     action="set-implementation"
  318.                 fi                
  319.  
  320.                 if is_number ${opt} ; then
  321.                     targets=( $(get_implementations) )
  322.                     new=${targets[$(( ${opt} - 1 ))]}
  323.                     if [[ -z ${new} ]] ; then
  324.                         die -q "Unrecognized option: ${opt}"
  325.                     fi
  326.                 elif has ${opt} ${available}; then
  327.                     new="${opt}"
  328.                 else
  329.                     die -q "Unrecognized option: ${opt}"
  330.                 fi
  331.             ;;
  332.         esac
  333.     done
  334.  
  335.     case ${action} in
  336.         old-implementation)
  337.             set_new_implementation ${current}
  338.             return $?
  339.         ;;
  340.         set-implementation)
  341.             if [[ -n ${new} ]] ; then
  342.                 set_new_implementation ${new}
  343.                 return $?
  344.             else
  345.                 die -q "Please specify an implementation to set"
  346.             fi
  347.         ;;
  348.         *)
  349.             die -q "Invalid usage of set action."
  350.         ;;
  351.     esac
  352. }
  353.